<!doctype html>
<html lang="zh-CN">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <meta name="referrer" content="no-referrer-when-downgrade">
    

    <title>cloudstack-4.1.5版本最全入门笔记【2022】 | Sang的博客</title>
    <meta property="og:title" content="cloudstack-4.1.5版本最全入门笔记【2022】 - Sang的博客">
    <meta property="og:type" content="article">
        
    <meta property="article:published_time" content='2021-11-23T11:32:18&#43;08:00'>
        
        
    <meta property="article:modified_time" content='2021-11-23T11:32:18&#43;08:00'>
        
    <meta name="Keywords" content="golang,go语言,shell,k8s,博客,python,软件架构,公众号">
    <meta name="description" content="cloudstack-4.1.5版本最全入门笔记【2022】">
        
    <meta name="author" content="仨哥">
    <meta property="og:url" content="https://stto_32.gitee.io/site/post/cloudstack&#43;kvm/">
    <link rel="shortcut icon" href='/site/favicon.ico'  type="image/x-icon">

    <link rel="stylesheet" href='/site/css/normalize.css'>
    <link rel="stylesheet" href='/site/css/style.css'>
    <script type="text/javascript" src="//cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    
    
    
        <link href="https://cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css" rel="stylesheet">
    
    
    
    
        <link rel="stylesheet" href='/site/css/douban.css'>
    
        <link rel="stylesheet" href='/site/css/other.css'>
    
</head>


<body>
    <header id="header" class="clearfix">
    <div class="container">
        <div class="col-group">
            <div class="site-name ">
                
                    <a id="logo" href="https://stto_32.gitee.io/site">
                        Sang的博客
                    </a>
                
                <p class="description">专注于Python、Go语言(golang)、云原生</p>
            </div>
            <div>
                <nav id="nav-menu" class="clearfix">
                    <a class="current" href="https://stto_32.gitee.io/site">首页</a>
                    
                    <a  href="https://stto_32.gitee.io/site/tools/" title="小工具">小工具</a>
                    
                    <a  href="https://stto_32.gitee.io/site/archives/" title="归档">归档</a>
                    
                    <a  href="https://stto_32.gitee.io/site/about/" title="关于">关于</a>
                    
                </nav>
            </div>
        </div>
    </div>
</header>

    <div id="body">
        <div class="container">
            <div class="col-group">

                <div class="col-8" id="main">
                    
<div class="res-cons">
    
    <article class="post">
        <header>
            <h1 class="post-title">cloudstack-4.1.5版本最全入门笔记【2022】</h1>
        </header>
        <date class="post-meta meta-date">
            2021年11月23日
        </date>
        
        
        <div class="post-meta">
            <span id="busuanzi_container_page_pv">|<span id="busuanzi_value_page_pv"></span><span>
                    阅读</span></span>
        </div>
        
        
        <div class="post-content">
            <p>CloudStack是一个开源的具有高可用性及扩展性的云计算平台。目前Cloudstack支持管理大部分主流的hypervisors，如KVM，XenServer，VMware，Oracle VM，Xen等。同时CloudStack是一个开源云计算解决方案。可以加速高伸缩性的公共和私有云（IaaS）的部署、管理、配置。使用CloudStack作为基础，数据中心操作者可以快速方便的通过现存基础架构创建云服务。</p>
<h4 id="cloudstack概念架构"><strong>cloudstack概念架构</strong></h4>
<p>
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/d456a7acf21d4c88be884d51a996f827~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="1614317659268" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/d456a7acf21d4c88be884d51a996f827~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<blockquote>
<ul>
<li>用户：通过网络访问属于“我”的虚拟机、存储空间、管理“我”的个人模板。</li>
<li>管理员：部署配置，管理账户，监控资源，安排作业，排除故障。</li>
<li>开发人员：开发计费、监控、统计报表等功能模块，定制图形界面、工作流。</li>
</ul>
</blockquote>
<h4 id="cloudstack部署架构"><strong>cloudstack部署架构</strong></h4>
<p>
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/a848facc7c0343e4ac5dc89e362a54d7~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="1614318138954" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/a848facc7c0343e4ac5dc89e362a54d7~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<blockquote>
<p>上图中的各个组件介绍如下：</p>
<ul>
<li>
<p>Regions：为了提高云的可靠性，可以选择将资源分为多个地理区域。区域是CloudStack部署中最大的可用组织单位。一个区域由几个可用性zones组成，其中每个zone大致相当于一个数据中心。每个Regions均由其在一个zone中运行的管理服务器集群控制。regions中的zones通常相隔非常近。Regions 是用于提供容错和灾难恢复的有用技术。</p>
</li>
<li>
<p>Zone：Zone 对应于现实中的一个数据中心。</p>
</li>
<li>
<p>Pod：Pod 对应着一个机架。同一个 pod 中的机器在同一个子网（网段）中。</p>
</li>
<li>
<p>Cluster：Cluster 是多个主机组成的一个集群。同一个 cluster 中的主机有相同的硬件，相同的 Hypervisor，和共用同样的存储。同一个 cluster 中的虚拟机，可以实现无中断服务地从一个主机迁移到另外一个上。</p>
</li>
<li>
<p>Host：Host 就是运行虚拟机（VM）的主机。</p>
</li>
</ul>
<ul>
<li><code>CloudStack</code>存储按用途分为<code>主存储(Primary Storage)</code>和<code>二级存储(Secondary Storage)</code>，主存储用来存储<code>虚拟机的卷</code>,二级存储用来存放<code>虚拟机的模板，ISO镜像和快照</code></li>
</ul>
<ul>
<li>
<p>Primary storage：一级存储与 cluster 关联，它为该 cluster 中的主机的全部虚拟机提供磁盘卷。一个 cluster 至少有一个一级存储，且在部署时位置要临近主机以提供高性能。</p>
</li>
<li>
<p>Secondary storage：二级存储与 zone 关联，它存储模板文件，ISO 镜像和磁盘卷快照。</p>
</li>
<li>
<ul>
<li>模板：可以启动虚拟机的操作系统镜像，也包括了诸如已安装应用的其余配置信息。</li>
<li>ISO 镜像：包含操作系统数据或启动媒质的磁盘镜像。</li>
<li>磁盘卷快照：虚拟机数据的已储存副本，能用于数据恢复或者创建新模板。</li>
</ul>
</li>
</ul>
</blockquote>
<p>即从包含关系上来说，一个regions包含多个zone，一个 zone 包含多个 pod，一个 pod 包含多个 cluster，一个 cluster 包含多个 host。</p>
<h4 id="cloudstack和kvm一起部署的架构"><strong>cloudstack和kvm一起部署的架构</strong></h4>
<p>
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/0c08fc823851418f9a92a03c2f4298ed~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="1614319012106" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/0c08fc823851418f9a92a03c2f4298ed~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<p>如上所述：在每个kvm的宿主机上都需要部署agent程序。</p>
<p>如果部署vmware的产品就必须部署vcenter server。</p>
<h4 id="cloudstack部署实践"><strong>cloudstack部署实践</strong></h4>
<p>关于这部分内容，请阅读<a href="http://docs.cloudstack.apache.org/en/4.15.0.0/conceptsandterminology/choosing_deployment_architecture.html">官方文档</a>。</p>
<p>主要是介绍cloudstack支持的存储协议、架构模式、机器配置等建议。</p>
<h4 id="cloudstack和openstack比较"><strong>cloudstack和openstack比较</strong></h4>
<table>
<thead>
<tr>
<th></th>
<th><strong>难易度</strong></th>
<th><strong>适合规模</strong></th>
<th><strong>参考资料</strong></th>
<th><strong>是否开源</strong></th>
<th><strong>市场占有率</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>cloudstack</td>
<td>组件少，较易</td>
<td>小、中、大</td>
<td>较少</td>
<td>是</td>
<td>低</td>
</tr>
<tr>
<td>openstack</td>
<td>组件多，较难</td>
<td>中、大</td>
<td>较多</td>
<td>是</td>
<td>高</td>
</tr>
</tbody>
</table>
<h3 id="部署cloudstack"><strong>部署cloudstack</strong></h3>
<h4 id="环境准备"><strong>环境准备</strong></h4>
<table>
<thead>
<tr>
<th><strong>OS</strong></th>
<th><strong>主机名</strong></th>
<th><strong>IP</strong></th>
<th><strong>rules</strong></th>
<th><strong>services</strong></th>
<th><strong>explain</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>cenots 7.7</td>
<td>management</td>
<td>10.10.10.5</td>
<td>管理节点</td>
<td>chronyd、cloudstack-management、mariadb、nginx</td>
<td>用于管理整个cloudstack，最少2c4g</td>
</tr>
<tr>
<td>cenots 7.7</td>
<td>kvm1</td>
<td>10.10.10.22</td>
<td>计算节点</td>
<td>kvm</td>
<td>用于运行租户创建的虚拟机，建议4c4g</td>
</tr>
<tr>
<td>cenots 7.7</td>
<td>nfs</td>
<td>10.10.10.5</td>
<td>存储节点</td>
<td>nfs</td>
<td>提供主存储、二级存储，最少2g1c，一块100G磁盘</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<h4 id="系统初始化"><strong>系统初始化</strong></h4>
<p>系统初始化这一小节，如果没有特别说明，均需在所有节点执行。</p>
<h4 id="修改主机名"><strong>修改主机名</strong></h4>
<div class="highlight"><div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">
$ hostnamectl set-hostname management

$ hostnamectl set-hostname kvm1

$ hostnamectl set-hostname nfs
source /etc/profile
</code></pre></td></tr></table>
</div>
</div><h4 id="关闭防火墙及selinux"><strong>关闭防火墙及selinux</strong></h4>
<p>在生产环境中，建议防火墙放行内网网段即可。selinux设置为permissive模式。（视频资料中说selinux设置为disable会有问题，具体待验证。）</p>
<div class="highlight"><div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">8
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">
$ systemctl stop firewalld &amp;&amp; systemctl disable firewalld

setenforce 0

sed -i &#39;s#^SELINUX=.*#SELINUX=permissive#g&#39; /etc/selinux/config

sed -i &#39;s#^SELINUX=.*#SELINUX=permissive#g&#39; /etc/sysconfig/selinux
</code></pre></td></tr></table>
</div>
</div><h4 id="配置yum源"><strong>配置yum源</strong></h4>
<p>这一步主要是将默认的国外yum源配置为国内阿里的yum，如果你有自己内网的yum源服务器，请跳过此步骤。</p>
<div class="highlight"><div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback"># 更换为阿里云源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
cat &gt; /etc/yum.repos.d/cloudstack.repo &lt;&lt; &#39;EOF&#39;
[cloudstack]
name=cloudstack
baseurl=http://download.cloudstack.org/centos/$releasever/4.15/
enabled=1
gpgcheck=0
EOF
</code></pre></td></tr></table>
</div>
</div><h4 id="配置nfs服务"><strong>配置nfs服务</strong></h4>
<p>（此步骤在nfs节点执行）</p>
<div class="highlight"><div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback"> yum -y install nfs-utils

cat &gt;&gt; /etc/exports &lt;&lt; EOF

/export/secondary *(rw,async,no_root_squash,no_subtree_check)

/export/primary *(rw,async,no_root_squash,no_subtree_check)

EOF
# 创建共享目录
mkdir /export/{primary,secondary}
# 启动nfs
systemctl enable rpcbind nfs
systemctl start rpcbind nfs
其他任意节点确保可查看到共享目录：
showmount -e 10.10.10.5
</code></pre></td></tr></table>
</div>
</div><h4 id="安装cloudstack-management"><strong>安装cloudstack-management</strong></h4>
<p><code>yum install -y cloudstack-management cloudstack-common</code></p>
<h4 id="导入数据库此处使用已有的mysql作为存储"><strong>导入数据库（此处使用已有的mysql作为存储）</strong></h4>
<div class="highlight"><div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback"># 可通过 cloudstack-setup-databases --help 查看其他命令选项及其含义
$ cloudstack-setup-databases cloud:epai706@localhost:3306 --deploy-as=root:epai706
# cloud:epai706：表示执行成功后，mysql数据库将创建一个密码为epai706的cloud用户供管理节点使用。
# --deploy-as：指定你本次使用哪个数据库用户导入数据
</code></pre></td></tr></table>
</div>
</div><p>输出如下信息，表示数据库初始化成功：</p>
<p>
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/44e45bcffc544eb1b13c6576830536e0~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="1614335594963" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/44e45bcffc544eb1b13c6576830536e0~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<h4 id="启动manager-server"><strong>启动manager server</strong></h4>
<div class="highlight"><div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback"># 第一次启动请这样启动

$ cloudstack-setup-management

# 执行后将输出如下信息，则表示启动成功：

Starting to configure CloudStack Management Server:

Configure Firewall ... [OK]

Configure CloudStack Management Server ...[OK]

CloudStack Management Server setup is Done!
# 后续启动方式请使用
$ systemctl restart cloudstack-management
</code></pre></td></tr></table>
</div>
</div><h4 id="访问dashboard"><strong>访问dashboard</strong></h4>
<p>访问management的8080端口，可以看到如下界面，则表示management安装成功（默认用户名/密码：admin/password）：</p>
<p>
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/dec90107458a4661874bfa9387298e28~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="image-20220210170709372" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/dec90107458a4661874bfa9387298e28~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<h4 id="上传系统虚机镜像"><strong>上传系统虚机镜像</strong></h4>
<p>cloudstack默认依赖几个虚机运行，当cloudstack添加区域后，他将自动启动相关虚机，所以还需要将镜像导入到二级存储中。</p>
<p>下载虚拟机<code>系统模板</code>,放到<code>二级存储</code>目录上</p>
<div class="highlight"><div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#75715e">#官方下载地址http://cloudstack.apt-get.eu/systemvm/4.15/</span>
wget http://cloudstack.apt-get.eu/systemvm/4.15/systemvmtemplate-4.15.0-kvm.qcow2.bz2 
wget http://cloudstack.apt-get.eu/systemvm/4.15/systemvmtemplate-4.15.0-vmware.ova
wget http://cloudstack.apt-get.eu/systemvm/4.15/systemvmtemplate-4.15.0-ovm.raw.bz2
wget http://cloudstack.apt-get.eu/systemvm/4.15/systemvmtemplate-4.15.0-xen.vhd.bz2
wget http://cloudstack.apt-get.eu/systemvm/4.15/systemvmtemplate-4.15.0-hyperv.vhd.zip

</code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">8
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#75715e">#kvm</span>
/usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt <span style="color:#ae81ff">\
</span><span style="color:#ae81ff"></span>-m /export/secondary  -f /root/systemvmtemplate-4.15.0-kvm.qcow2.bz2  -h kvm -F

<span style="color:#75715e">#vmware</span>
/usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt <span style="color:#ae81ff">\
</span><span style="color:#ae81ff"></span>-m /export/secondary  -f /root/systemvmtemplate-4.15.0-vmware.ova  -h vmware -F

</code></pre></td></tr></table>
</div>
</div><p>输出如下，则表示上传成功：</p>
<p>
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/ecaa3c34a36c4fb79ac56853aab5774b~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="1614339908396" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/ecaa3c34a36c4fb79ac56853aab5774b~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<h4 id="配置计算节点"><strong>配置计算节点</strong></h4>
<p>注：此步骤只需在计算节点上执行。</p>
<h5 id="修改网络配置"><strong>修改网络配置</strong></h5>
<p>主要是生成一个网桥设备，以便VM都可以连接到此网桥。</p>
<div class="highlight"><div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">21
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">22
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">23
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback"># 备份源网卡配置文件
$ cp /etc/sysconfig/network-scripts/ifcfg-ens33{,_$(date +%F_%H).bak}
# 修改网卡配置文件
cat &gt; /etc/sysconfig/network-scripts/ifcfg-ens33 &lt;&lt; EOF
TYPE=Ethernet
DEVICE=ens33
ONBOOT=yes
BRIDGE=cloudbr0
EOF

cat &gt; /etc/sysconfig/network-scripts/ifcfg-cloudbr0 &lt;&lt; EOF
DEVICE=cloudbr0
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=static
IPADDR=10.10.10.22
GATEWAY=10.10.10.1
DNS1=223.5.5.5
EOF
# 修改完成后，务必检查是否修改正确，网卡名称、IP地址与你的实际环境是否一致
# 确认无误后，重启网络服务

$ systemctl restart network
</code></pre></td></tr></table>
</div>
</div><h5 id="安装cloudstack-agent"><strong>安装cloudstack-agent</strong></h5>
<div class="highlight"><div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">yum -y install cloudstack-agent cloudstack-common
</code></pre></td></tr></table>
</div>
</div><h5 id="确认加载kvm模块"><strong>确认加载kvm模块</strong></h5>
<div class="highlight"><div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">$ lsmod | grep kvm # 输出如下，则表示已加载
[root@WT-TEST-10-22 ~]# lsmod | grep kvm
kvm_intel             188688  15 
kvm                   636969  1 kvm_intel
irqbypass              13503  21 kvm
[root@WT-TEST-10-22 ~]# 
</code></pre></td></tr></table>
</div>
</div><h5 id="安装ibvirt"><strong>安装ibvirt</strong></h5>
<p><code>yum -y install qemu-kvm libvirt python-virtinst bridge-utils</code></p>
<p><strong>修改libvirt默认配置</strong></p>
<div class="highlight"><div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">修改vnc默认监听地址

sed -i &#39;s/^#vnc_listen =.*/vnc_listen = &#34;0.0.0.0&#34;/g&#39; /etc/libvirt/qemu.conf
# 指定cloudstack-management地址
sed -i &#34;s/host=.*/host=10.10.10.5/g&#34; /etc/cloudstack/agent/agent.properties
# 重启libvirt
systemctl restart libvirtd
</code></pre></td></tr></table>
</div>
</div><h5 id="启动cloudstack-agent并加入开机自启"><strong>启动cloudstack-agent并加入开机自启</strong></h5>
<p><code>$ systemctl start cloudstack-agent &amp;&amp; systemctl enable cloudstack-agent</code></p>
<h4 id="规划cloustack网络"><strong>规划cloustack网络</strong></h4>
<p>在cloudstack中，提供了两种网络：基本网络和高级网络。这篇博文将基于基本网络进行配置，如果要配置高级网络，那么这篇博文不用继续往下看了，移步即可。</p>
<h5 id="基本网络"><strong>基本网络</strong></h5>
<p>基本网络模式采用传统扁平网络，与现有网络完美兼容，其网络通信拓扑如下：</p>
<p>
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/46bbbf86a4bd498592d758a01b701075~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="1614324293753" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/46bbbf86a4bd498592d758a01b701075~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<p>基础网络模式只提供了简单的网络模型，管理网络、来宾网络、存储网络、V-Route（只提供了DNS、dhcp，并不提供网关服务）等。</p>
<h5 id="高级网络"><strong>高级网络</strong></h5>
<p>高级网络模式中，每个租户获得一个或多个来宾网络，每个网络属于独立的VLAN，由虚拟路由器为这些来宾网络提供网关服务。</p>
<p>虚拟路由器（系统虚拟机提供）在高级网络中十分重要，它将成为租户私有网络与公共网络之间的接口，并未租户私有网络提供各种网络服务，包括NAT、静态NAT、DHCP、DNS、Load Balancing、Port Forwording、Firewalls、Site-to-Site 虚拟专用网、VPC等。</p>
<p>高级网络架构图如下：
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/d051b432710b4c29b80746f2da56dc3c~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="1614324480867" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/d051b432710b4c29b80746f2da56dc3c~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<p>两种不同的网络，对来宾网络（Guest Network）采用的隔离方式不同，在基本模式下，采用安全组（Security Group）方式进行隔离；而在高级网络中，采用VLAN方式进行隔离。</p>
<h4 id="具体网络规划内网实验用"><strong>具体网络规划(内网实验用)</strong></h4>
<table>
<thead>
<tr>
<th><strong>角色</strong></th>
<th><strong>网络</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>management+nfs</td>
<td>10.10.10.5</td>
</tr>
<tr>
<td>kvm1</td>
<td>10.10.10.22</td>
</tr>
<tr>
<td>虚拟机(来宾网络)</td>
<td>10.10.10.150-10.10.10.160</td>
</tr>
</tbody>
</table>
<h5 id="创建zone"><strong>创建zone</strong></h5>
<p>登录到cloudstack-management的管理控制台，进行如下操作，以便添加第一个zone：</p>
<p>1、网络选择基本的：
<!-- raw HTML omitted -->
2、资源域详细信息：</p>
<blockquote>
<p>网络方案介绍：</p>
<ul>
<li>
<p>DefaultSharedNetworkOfferingWithSGService：带有安全组的网络方案，推荐选择此选项。</p>
</li>
<li>
<p>DefaultSharedNetworkOffering：不带安全组功能。</p>
</li>
<li>
<p>DefaultSharedNetscalerEIPandELBNetworkOffering：如果你在CLOUDSTACK内安装了Citrix NetScaler应用，并且你需要Elastic IP和Elastic Load Balancing这些功能的话，那就选择这个选项。EIP 和ELB技术在安全组启用的情况下，可以提供1：1的NAT映射和负载均衡功能。此功能需要citrix硬件支持，一般很少用。</p>
</li>
<li>
<p>QuickCloudNoServices：表示什么都不用，新增选项，不建议使用。</p>
</li>
</ul>
</blockquote>
<p><!-- raw HTML omitted --></p>
<p>3、网络</p>
<p><!-- raw HTML omitted --></p>
<p>4、添加提供点</p>
<p><!-- raw HTML omitted --></p>
<p>5、设置来宾网络</p>
<p><!-- raw HTML omitted --></p>
<p>6、设置群集名称</p>
<p><!-- raw HTML omitted --></p>
<p>7、添加kvm主机节点</p>
<p><!-- raw HTML omitted --></p>
<p>8、配置主存储</p>
<p><!-- raw HTML omitted --></p>
<p>9、配置二级存储</p>
<p><!-- raw HTML omitted --></p>
<p>11、启用资源域</p>
<p>激动人心的时刻到了，这一步，将检验你之前所有的操作是否正确。</p>
<p><!-- raw HTML omitted --></p>
<h4 id="验证cloudstack可用性"><strong>验证cloudstack可用性</strong></h4>
<p>至此，你必须保证下面的任意资源都为“UP” 状态，如下：</p>
<p><code>1、资源域状态为“Enabled”</code></p>
<p><code>2、提供点状态状态为“Enabled”</code></p>
<p><code>3、群集状态“Enabled”</code></p>
<p><code>4、主机状态必须为 “Up”</code></p>
<p><code>5、主存储状态必须为 “Up”</code></p>
<p><code>6、二级存储状态必须为 “Up”</code></p>
<p><code>7、系统VM必须正常状态必须为 “Up”</code></p>
<p>至此，可以说你的集群完全可用了，但虚拟路由器现在数量为 “0”，当我们创建第一个实例后，虚拟路由器就被创建了。</p>
<h4 id="注册iso"><strong>注册ISO</strong></h4>
<p>现在，我们就来启动一个实例进行验证。需要自行准备一张系统盘。最好是centos的。附：<a href="http://mirrors.163.com/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso">centos镜像下载链接</a>。</p>
<p>注册ISO镜像支持两种方式，一种是从本地上传，一种是从一个URL主机，为了速度考虑，建议自行准备http服务器，然后配置为文件服务器，进行注册ISO（本地上传功能不靠谱）。</p>
<p>1、安装nginx</p>
<p>任意节点安装即可，既然博文开头规划在了management节点，那就在这个节点吧。</p>
<div class="highlight"><div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">server <span style="color:#f92672">{</span>
    listen 80;
    server_name  10.10.10.5;
location / <span style="color:#f92672">{</span>
root /data;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
<span style="color:#f92672">}</span>
<span style="color:#f92672">}</span>
<span style="color:#75715e">#可以看到在正常下载即可：</span>
wget http://10.10.10.5/CentOS-7-x86_64-DVD-2009.iso
</code></pre></td></tr></table>
</div>
</div><p>2、定义允许哪些网络可以访问二级存储（<code>不配置iso安装的时候会拒绝</code>）</p>
<p>
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/17f07f7040f14f03825184f6f02e9328~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="image-20220211140151997" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/17f07f7040f14f03825184f6f02e9328~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<p>3、重启cloudstack-management生效</p>
<p><code>systemctl restart cloudstack-management</code></p>
<p>重启后，需要稍等片刻，待8080端口在监听，才可以继续访问控制台：</p>
<p>4、注册ISO</p>
<p>访问控制台，进行如下操作：</p>
<p>
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/a1fb5d5283bd4d88882f67ba8c03e78a~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="image-20220211110611827" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/a1fb5d5283bd4d88882f67ba8c03e78a~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<p>查看镜像上传进度：</p>
<p>自行刷新页面，直至完成：</p>
<p>稍等片刻，看到镜像状态如下，则表示成功：</p>
<p>
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/a86429bfaa824255a0953123e0954985~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="image-20220210174132652" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/a86429bfaa824255a0953123e0954985~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<h4 id="创建vm虚拟机">创建vm虚拟机</h4>
<p>
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/2c206f6bf10844ceb0e4e0514dff35b2~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="网页捕获_10-2-2022_181546_10.10.10.5" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/2c206f6bf10844ceb0e4e0514dff35b2~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<p>启动VM后，<code>进入虚机控制台,则可以和正常一样装系统了</code>：</p>
<p>
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/531d2f8834fa4607a8153061d5926d45~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="image-20220211111151250" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/531d2f8834fa4607a8153061d5926d45~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<p>此处省略一万字&hellip;&hellip;&hellip;&hellip;&hellip;</p>
<h4 id="取消附加iso"><strong>取消附加ISO</strong></h4>
<p>当装完系统后，重启VM，默认还会进入装系统的界面，我们需要进行如下操作，才可以正常使用虚机，如下（需在VM关机状态下执行）：</p>
<p>
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/f85c1ea453714941b7794624f04d2336~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="image-20220211112640542" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/f85c1ea453714941b7794624f04d2336~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<h4 id="安装centos系统后-没有ip地址"><code>安装centos系统后 ，没有IP地址</code></h4>
<ul>
<li><strong>配置网卡及初始化系统</strong></li>
</ul>
<div class="highlight"><div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">21
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">22
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">23
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">24
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#75715e">#必须要修改网络接口的配置文件，编辑/etc/sysconfig/network-scripts/ifcfg-eth0文件</span>
DEVICE<span style="color:#f92672">=</span>eth0
TYPE<span style="color:#f92672">=</span>Ethernet
BOOTPROTO<span style="color:#f92672">=</span>dhcp
ONBOOT<span style="color:#f92672">=</span>yes
DNS1<span style="color:#f92672">=</span>223.5.5.5
<span style="color:#75715e">#----------系统初始化操作可以放在此处---------------------</span>
<span style="color:#75715e">#移除udev持久设备规则</span>
rm -f /etc/udev/rules.d/70*
rm -f /var/lib/dhclient/*
<span style="color:#75715e">#移除SSH Keys这步是为了确认所有要作为模板的VMs的SSH Keys都不相同，否则这样会降低虚拟机的安全性。</span>
rm -f /etc/ssh/*key*
<span style="color:#75715e">#清除日志文件,从主模板移除旧的日志文件是一个好习惯。</span>
cat /dev/null &gt; /var/log/audit/audit.log 2&gt;/dev/null1
cat /dev/null &gt; /var/log/wtmp 2&gt;/dev/null
logrotate -f /etc/logrotate.conf 2&gt;/dev/null
rm -f /var/log/*-* /var/log/*.gz 2&gt;/dev/null
<span style="color:#75715e">#清除用户历史bash命令。</span>
history -c
unset HISTFILE
<span style="color:#75715e">#关闭selinux和防火墙</span>
sed -i <span style="color:#e6db74">&#34;s/SELINUX=enforcing/SELINUX=disable/g&#34;</span> /etc/selinux/config
systemctl stop firewalld.service;systemctl disable firewalld.service

</code></pre></td></tr></table>
</div>
</div><ul>
<li><strong>关闭VM</strong></li>
<li><strong>基于关闭vm的模板并且创建<code>新模板</code></strong></li>
</ul>
<p>从当前实例进来，点击<code>**卷**</code></p>
<p>
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/d5d43b0020794ca9b083d77e5beb496e~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="image-20220211135258662" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/d5d43b0020794ca9b083d77e5beb496e~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<p>基于卷创建模板</p>
<p>
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/2eff1443a14242c9908c5d310b99a5cb~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="image-20220211135335267" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/2eff1443a14242c9908c5d310b99a5cb~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<p>
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/df6f07d536794c92a9eef1c67745648e~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="image-20220211135414820" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/df6f07d536794c92a9eef1c67745648e~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<p>等待最终模板的状态是&quot;<strong><code>Download Complete</code></strong>&quot;</p>
<p>
        <a data-fancybox="gallery" href="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/751073e4ae8249769736314208a56c50~tplv-k3u1fbpfcp-zoom-1.image">
            <img class="mx-auto" alt="image-20220211140055511" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/751073e4ae8249769736314208a56c50~tplv-k3u1fbpfcp-zoom-1.image" />
        </a>
    </p>
<p>从此可以使用&quot;<strong><code>tmp_centos7</code></strong>&ldquo;模板创建虚拟机了</p>
<h4 id="api操作">API操作</h4>
<div class="highlight"><div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">21
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">22
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">23
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">24
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">25
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">26
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">27
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">28
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">29
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">30
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">31
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">32
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">33
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">34
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">35
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">36
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">37
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">38
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">39
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">40
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">41
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">42
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">43
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">44
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">45
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">46
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">47
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">48
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">49
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">50
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">51
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">52
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">53
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">54
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">55
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">56
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">57
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">58
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">59
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">60
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">61
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">62
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#75715e">#!/usr/bin/env python</span>
<span style="color:#75715e"># -*- coding:utf-8 -*-</span>
<span style="color:#75715e"># @Time    : 2022/2/11 14:41</span>
<span style="color:#75715e"># @Author  : XuLiLiang</span>
<span style="color:#75715e"># @File    : cloudstack-api.py</span>
<span style="color:#f92672">import</span> base64
<span style="color:#f92672">import</span> hashlib
<span style="color:#f92672">import</span> hmac
<span style="color:#f92672">import</span> json

<span style="color:#f92672">import</span> requests
<span style="color:#f92672">from</span> urllib <span style="color:#f92672">import</span> parse

baseurl <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;http://10.10.10.5:8080/client/api?&#39;</span>
api_key <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;g1Z0AutTl4Fbl3OeNX_rLJjaecOwMHkY3iUy6OiXlC6S3deP4s2NeLM2u8hGLqBHz509CHeC9eInPGvAqJ5KBg&#39;</span>
secret_key <span style="color:#f92672">=</span> <span style="color:#e6db74">b</span><span style="color:#e6db74">&#39;MiX6r_vBgO3c9ZUnadq8aOzHg18Y0FnHjP-NPLfCcS1wOsLYcoJdVXEU4aUK6reHjsB7Z4sP4pQbV8yLLmzIyA&#39;</span>


<span style="color:#66d9ef">class</span> <span style="color:#a6e22e">CloudApi</span>:
    <span style="color:#66d9ef">def</span> __init__(self):
        self<span style="color:#f92672">.</span>baseurl <span style="color:#f92672">=</span> baseurl
        self<span style="color:#f92672">.</span>api_key <span style="color:#f92672">=</span> api_key
        self<span style="color:#f92672">.</span>secret_key <span style="color:#f92672">=</span> secret_key

    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">GetSing</span>(self, command,<span style="color:#f92672">**</span>kwargs):
        request <span style="color:#f92672">=</span> {}
        request[<span style="color:#e6db74">&#39;command&#39;</span>] <span style="color:#f92672">=</span> command
        request[<span style="color:#e6db74">&#39;response&#39;</span>] <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;json&#39;</span>
        request[<span style="color:#e6db74">&#39;apikey&#39;</span>] <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>api_key
        <span style="color:#66d9ef">for</span> k,v <span style="color:#f92672">in</span> kwargs<span style="color:#f92672">.</span>items():
            request[k]<span style="color:#f92672">=</span>v
        request_str <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;&amp;&#39;</span><span style="color:#f92672">.</span>join([<span style="color:#e6db74">&#39;=&#39;</span><span style="color:#f92672">.</span>join([k, parse<span style="color:#f92672">.</span>quote_plus(request[k])]) <span style="color:#66d9ef">for</span> k <span style="color:#f92672">in</span> request<span style="color:#f92672">.</span>keys()])
        sig_str <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;&amp;&#39;</span><span style="color:#f92672">.</span>join([<span style="color:#e6db74">&#39;=&#39;</span><span style="color:#f92672">.</span>join([k<span style="color:#f92672">.</span>lower(), parse<span style="color:#f92672">.</span>quote_plus(request[k]<span style="color:#f92672">.</span>lower()<span style="color:#f92672">.</span>replace(<span style="color:#e6db74">&#39;+&#39;</span>, <span style="color:#e6db74">&#39;%20&#39;</span>))]) <span style="color:#66d9ef">for</span> k <span style="color:#f92672">in</span>
                            sorted(request<span style="color:#f92672">.</span>keys())])<span style="color:#f92672">.</span>encode(<span style="color:#e6db74">&#34;utf-8&#34;</span>)
        sig <span style="color:#f92672">=</span> hmac<span style="color:#f92672">.</span>new(self<span style="color:#f92672">.</span>secret_key, sig_str, hashlib<span style="color:#f92672">.</span>sha1)<span style="color:#f92672">.</span>digest()
        sig <span style="color:#f92672">=</span> base64<span style="color:#f92672">.</span>encodebytes(hmac<span style="color:#f92672">.</span>new(self<span style="color:#f92672">.</span>secret_key, sig_str, hashlib<span style="color:#f92672">.</span>sha1)<span style="color:#f92672">.</span>digest())
        sig <span style="color:#f92672">=</span> base64<span style="color:#f92672">.</span>encodebytes(hmac<span style="color:#f92672">.</span>new(self<span style="color:#f92672">.</span>secret_key, sig_str, hashlib<span style="color:#f92672">.</span>sha1)<span style="color:#f92672">.</span>digest())<span style="color:#f92672">.</span>strip()
        sig <span style="color:#f92672">=</span> parse<span style="color:#f92672">.</span>quote_plus(base64<span style="color:#f92672">.</span>encodebytes(hmac<span style="color:#f92672">.</span>new(self<span style="color:#f92672">.</span>secret_key, sig_str, hashlib<span style="color:#f92672">.</span>sha1)<span style="color:#f92672">.</span>digest())<span style="color:#f92672">.</span>strip())

        req <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>baseurl <span style="color:#f92672">+</span> request_str  <span style="color:#f92672">+</span> <span style="color:#e6db74">&#39;&amp;signature=&#39;</span> <span style="color:#f92672">+</span> sig
        <span style="color:#66d9ef">return</span> req

    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">listClusters</span>(self):
        req<span style="color:#f92672">=</span>self<span style="color:#f92672">.</span>GetSing(<span style="color:#e6db74">&#39;listClusters&#39;</span>)
        s <span style="color:#f92672">=</span> requests<span style="color:#f92672">.</span>get(req)
        print(json<span style="color:#f92672">.</span>loads(s<span style="color:#f92672">.</span>content<span style="color:#f92672">.</span>decode(<span style="color:#e6db74">&#34;utf-8&#34;</span>))[<span style="color:#e6db74">&#39;listclustersresponse&#39;</span>][<span style="color:#e6db74">&#39;cluster&#39;</span>])

    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">listVirtualMachines</span>(self):
        req <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>GetSing(<span style="color:#e6db74">&#39;listVirtualMachines&#39;</span>)
        s <span style="color:#f92672">=</span> requests<span style="color:#f92672">.</span>get(req)
        print(json<span style="color:#f92672">.</span>loads(s<span style="color:#f92672">.</span>content<span style="color:#f92672">.</span>decode(<span style="color:#e6db74">&#34;utf-8&#34;</span>))[<span style="color:#e6db74">&#39;listvirtualmachinesresponse&#39;</span>][<span style="color:#e6db74">&#39;virtualmachine&#39;</span>])
    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">listTemplates</span>(self):
        req <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>GetSing(<span style="color:#e6db74">&#39;listTemplates&#39;</span>,templatefilter<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;all&#39;</span>,aaa<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;123123&#39;</span>)
        s <span style="color:#f92672">=</span> requests<span style="color:#f92672">.</span>get(req)
        response<span style="color:#f92672">=</span>json<span style="color:#f92672">.</span>loads(s<span style="color:#f92672">.</span>content<span style="color:#f92672">.</span>decode(<span style="color:#e6db74">&#34;utf-8&#34;</span>))[<span style="color:#e6db74">&#39;listtemplatesresponse&#39;</span>][<span style="color:#e6db74">&#39;template&#39;</span>]
        print(response)

<span style="color:#66d9ef">if</span> __name__ <span style="color:#f92672">==</span> <span style="color:#e6db74">&#39;__main__&#39;</span>:
    api <span style="color:#f92672">=</span> CloudApi()
    api<span style="color:#f92672">.</span>listVirtualMachines()
    api<span style="color:#f92672">.</span>listClusters()
    api<span style="color:#f92672">.</span>listTemplates()
</code></pre></td></tr></table>
</div>
</div>
        </div>

        
<div class="post-archive">
    <ul class="post-copyright">
        <li><strong>原文作者：</strong><a rel="author" href="https://stto_32.gitee.io/site">仨哥</a></li>
        <li style="word-break:break-all"><strong>原文链接：</strong><a href="https://stto_32.gitee.io/site/post/cloudstack&#43;kvm/">https://stto_32.gitee.io/site/post/cloudstack&#43;kvm/</a></li>
        <li><strong>版权声明：</strong>本作品采用<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/">知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议</a>进行许可，非商业转载请注明出处（作者，原文链接），商业转载请联系作者获得授权。</li>
    </ul>
</div>
<br/>



        

<div class="post-archive">
    <h2>See Also</h2>
    <ul class="listing">
        
        <li><a href="/site/post/%E5%9F%BA%E4%BA%8E1.22.1%E7%89%88%E6%9C%AC%E7%9A%84k8s%E9%83%A8%E7%BD%B2/">【2022】最详细的k8s基于1.22.1版本部署</a></li>
        
        <li><a href="/site/post/casbin/">casbin权限管理</a></li>
        
        <li><a href="/site/post/glusterfs%E5%AE%89%E8%A3%85/">glusterfs安装</a></li>
        
        <li><a href="/site/post/go%E4%B9%8Bnginx%E6%97%A5%E5%BF%97%E5%88%86%E6%9E%90/">go之nginx日志分析</a></li>
        
        <li><a href="/site/post/%E4%BA%BA%E4%BA%BA%E8%83%BD%E7%9C%8B%E6%87%82%E7%9A%84Async-Go/">go异步</a></li>
        
    </ul>
</div>


        <div class="post-meta meta-tags">
            
            <ul class="clearfix">
                
                <li><a href='/site/tags/kvm'>kvm</a></li>
                
                <li><a href='/site/tags/cloudstack'>cloudstack</a></li>
                
                <li><a href='/site/tags/%E4%BA%91%E5%8E%9F%E7%94%9F'>云原生</a></li>
                
            </ul>
            
        </div>
    </article>
    
    <div id="disqus_thread"></div>
<script type="application/javascript">
    var disqus_config = function () {
    
    
    
    };
    (function() {
        if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
            document.getElementById('disqus_thread').innerHTML = 'Disqus comments not available by default when the website is previewed locally.';
            return;
        }
        var d = document, s = d.createElement('script'); s.async = true;
        s.src = '//' + "xull" + '.disqus.com/embed.js';
        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

    
    
    <div class="post bg-white">
      <script src="https://utteranc.es/client.js"
            repo= "51op/hugoblogtalks"
            issue-term="pathname"
            theme="github-light"
            crossorigin="anonymous"
            async>
      </script>
    </div>
    
</div>

                    <footer id="footer">
    <div>
        &copy; 2022 <a href="https://stto_32.gitee.io/site">Sang的博客 By 仨哥</a>
        
    </div>
    <br />
    <div>
        <div class="github-badge">
            <a href="https://gohugo.io/" target="_black" rel="nofollow"><span class="badge-subject">Powered by</span><span class="badge-value bg-blue">Hugo</span></a>
        </div>
        <div class="github-badge">
            <a href="https://github.com/flysnow-org/maupassant-hugo" target="_black"><span class="badge-subject">Theme</span><span class="badge-value bg-yellowgreen">Maupassant</span></a>
        </div>
    </div>
</footer>


    
    <script type="text/javascript">
        window.MathJax = {
            tex2jax: {
                inlineMath: [['$', '$']],
                processEscapes: true
                }
            };
    </script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script><script src="https://cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js"></script>

<a id="rocket" href="#top"></a>
<script type="text/javascript" src='/site/js/totop.js?v=0.0.0' async=""></script>



    <script type="text/javascript" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>




    <script src='/site/js/douban.js'></script>

                </div>

                <div id="secondary">
    <section class="widget">
        <form id="search" action='https://stto_32.gitee.io/site/search/' method="get" accept-charset="utf-8" target="_blank" _lpchecked="1">
      
      <input type="text" name="q" maxlength="20" placeholder="Search">
      <input type="hidden" name="sitesearch" value="https://stto_32.gitee.io/site">
      <button type="submit" class="submit icon-search"></button>
</form>
    </section>
    
    <section class="widget">
        <h3 class="widget-title">最近文章</h3>
<ul class="widget-list">
    
    <li>
        <a href="https://stto_32.gitee.io/site/post/calico/" title="Calico网络之BGP详解">Calico网络之BGP详解</a>
    </li>
    
    <li>
        <a href="https://stto_32.gitee.io/site/post/casbin/" title="casbin权限管理">casbin权限管理</a>
    </li>
    
    <li>
        <a href="https://stto_32.gitee.io/site/post/cloudstack&#43;kvm/" title="cloudstack-4.1.5版本最全入门笔记【2022】">cloudstack-4.1.5版本最全入门笔记【2022】</a>
    </li>
    
    <li>
        <a href="https://stto_32.gitee.io/site/post/glusterfs%E5%AE%89%E8%A3%85/" title="glusterfs安装">glusterfs安装</a>
    </li>
    
    <li>
        <a href="https://stto_32.gitee.io/site/post/go%E4%B9%8Bnginx%E6%97%A5%E5%BF%97%E5%88%86%E6%9E%90/" title="go之nginx日志分析">go之nginx日志分析</a>
    </li>
    
    <li>
        <a href="https://stto_32.gitee.io/site/post/%E4%BA%BA%E4%BA%BA%E8%83%BD%E7%9C%8B%E6%87%82%E7%9A%84Async-Go/" title="go异步">go异步</a>
    </li>
    
    <li>
        <a href="https://stto_32.gitee.io/site/post/k8s%E7%8E%AF%E5%A2%83%E4%B8%8Bphp/" title="k8s环境php环境制品">k8s环境php环境制品</a>
    </li>
    
    <li>
        <a href="https://stto_32.gitee.io/site/post/kubernetes-client%E4%B9%8Bpython%E8%AF%A6%E7%BB%86%E6%8E%A5%E5%8F%A3%E8%B0%83%E7%94%A8/" title="kubernetes-client之python详细接口调用">kubernetes-client之python详细接口调用</a>
    </li>
    
    <li>
        <a href="https://stto_32.gitee.io/site/post/mac%E5%B7%A5%E5%85%B7/" title="mac工具">mac工具</a>
    </li>
    
    <li>
        <a href="https://stto_32.gitee.io/site/post/%E5%9F%BA%E4%BA%8E1.22.1%E7%89%88%E6%9C%AC%E7%9A%84k8s%E9%83%A8%E7%BD%B2/" title="【2022】最详细的k8s基于1.22.1版本部署">【2022】最详细的k8s基于1.22.1版本部署</a>
    </li>
    
</ul>
    </section>

    

    <section class="widget">
        <h3 class="widget-title"><a href='/site/categories/'>分类</a></h3>
<ul class="widget-list">
    
</ul>
    </section>

    <section class="widget">
        <h3 class="widget-title"><a href='/site/tags/'>标签</a></h3>
<div class="tagcloud">
    
    <a href="https://stto_32.gitee.io/site/tags/cloudstack/">cloudstack</a>
    
    <a href="https://stto_32.gitee.io/site/tags/k8s/">k8s</a>
    
    <a href="https://stto_32.gitee.io/site/tags/kvm/">kvm</a>
    
    <a href="https://stto_32.gitee.io/site/tags/php/">php</a>
    
    <a href="https://stto_32.gitee.io/site/tags/shell/">shell</a>
    
    <a href="https://stto_32.gitee.io/site/tags/%E4%BA%91%E5%8E%9F%E7%94%9F/">云原生</a>
    
</div>
    </section>

    
<section class="widget">
    <h3 class="widget-title">友情链接</h3>
    <ul class="widget-list">
        
        <li>
            <a target="_blank" href="https://www.cnblogs.com/xull0651/" title="Sang的博客">Sang的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="https://juejin.cn/user/2796746682943495" title="掘金">掘金</a>
        </li>
        
    </ul>
</section>


    <section class="widget">
        <h3 class="widget-title">其它</h3>
        <ul class="widget-list">
            <li><a href="https://stto_32.gitee.io/site/index.xml">文章 RSS</a></li>
        </ul>
    </section>
</div>
            </div>
        </div>
    </div>
</body>

</html>